source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-153.rds.xz")
summary(model)
SOM of size 5x5 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 156652 objects.
Mean distance to the closest unit in the map: 0.842.
plot(model, type="changes")
df <- mpr.load_data("datos_semana_2k.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:156652 Length:156652 Min. : 1.00 Min. :-109.0
Class :character Class :character 1st Qu.:13.00 1st Qu.: 147.0
Mode :character Mode :character Median :27.00 Median : 201.0
Mean :26.53 Mean : 202.1
3rd Qu.:40.00 3rd Qu.: 262.0
Max. :53.00 Max. : 442.0
tmin precip nevada prof_nieve
Min. :-189.00 Min. : 0.00 Min. :0 Min. : 0.000
1st Qu.: 48.00 1st Qu.: 0.00 1st Qu.:0 1st Qu.: 0.000
Median : 98.00 Median : 3.00 Median :0 Median : 0.000
Mean : 98.13 Mean : 16.92 Mean :0 Mean : 0.604
3rd Qu.: 152.00 3rd Qu.: 20.00 3rd Qu.:0 3rd Qu.: 0.000
Max. : 272.00 Max. :690.00 Max. :0 Max. :1073.000
longitud latitud altitud
Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.:39.01 1st Qu.: -4.850 1st Qu.: 44.0
Median :41.22 Median : -1.411 Median : 263.0
Mean :40.05 Mean : -2.426 Mean : 478.5
3rd Qu.:42.19 3rd Qu.: 1.272 3rd Qu.: 687.0
Max. :43.57 Max. : 4.216 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13
1619 13034 5882 5349 9756 5410 6322 4469 12863 5599 8683 5130 4831
14 15 16 17 18 19 20 21 22 23 24 25
5970 5633 6703 10019 5514 12055 5335 2132 9150 3211 1527 456
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 5*5;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "precip", "longitud", "latitud", "altitud")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt precip longitud latitud altitud
[1,] -0.4088161 -0.04241518 -0.6224200 -0.3070668 -0.567090
[2,] -0.6798965 0.25950245 0.4027636 0.2054039 0.452923
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
longitud latitud precip altitud fecha_cnt
0.9656268 0.9375270 0.9009239 0.8723928 0.8629843
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.0 Min. :-189.00 Min. : 0.00
1st Qu.:13.00 1st Qu.: 144.0 1st Qu.: 45.00 1st Qu.: 0.00
Median :27.00 Median : 196.0 Median : 93.00 Median : 4.00
Mean :26.53 Mean : 200.4 Mean : 93.73 Mean : 16.87
3rd Qu.:40.00 3rd Qu.: 262.0 3rd Qu.: 145.00 3rd Qu.: 22.00
Max. :53.00 Max. : 442.0 Max. : 272.00 Max. :223.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:39.88 1st Qu.: -4.049
Median :0 Median : 0.0000 Median :41.38 Median : -1.033
Mean :0 Mean : 0.6289 Mean :40.83 Mean : -1.519
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:42.24 3rd Qu.: 1.363
Max. :0 Max. :1073.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 58.0
Median : 316.0
Mean : 485.1
3rd Qu.: 704.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. : 1.0 Min. :-51.0 Min. : 0.000 Min. :0
1st Qu.:13.0 1st Qu.:211.0 1st Qu.:149.0 1st Qu.: 0.000 1st Qu.:0
Median :26.0 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.3 Mean :229.7 Mean :165.3 Mean : 5.343 Mean :0
3rd Qu.:39.0 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.0 Max. :384.0 Max. :263.0 Max. :155.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.03 Mean : 369.2
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-58.0 Min. :-103.00 Min. :193.0 Min. :0
1st Qu.:10.00 1st Qu.:102.0 1st Qu.: 42.00 1st Qu.:233.0 1st Qu.:0
Median :40.00 Median :139.0 Median : 80.50 Median :256.5 Median :0
Mean :29.92 Mean :135.9 Mean : 73.51 Mean :282.0 Mean :0
3rd Qu.:46.00 3rd Qu.:182.2 3rd Qu.: 117.00 3rd Qu.:309.2 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. : 217.00 Max. :690.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -5.742 1st Qu.: 66.7
Median : 0.000 Median :42.12 Median : -1.033 Median : 261.0
Mean : 5.531 Mean :40.78 Mean : -2.630 Mean : 696.9
3rd Qu.: 0.000 3rd Qu.:42.53 3rd Qu.: 1.168 3rd Qu.:1055.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-43 Min. :-80.00 Min. : 25.00 Min. :0
1st Qu.:13.00 1st Qu.:135 1st Qu.: 56.00 1st Qu.: 50.00 1st Qu.:0
Median :22.00 Median :170 Median : 87.00 Median : 65.00 Median :0
Mean :25.97 Mean :175 Mean : 88.62 Mean : 75.76 Mean :0
3rd Qu.:42.00 3rd Qu.:211 3rd Qu.:120.00 3rd Qu.: 91.00 3rd Qu.:0
Max. :53.00 Max. :407 Max. :247.00 Max. :223.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.95 1st Qu.: -4.846 1st Qu.: 58.0
Median : 0.0000 Median :41.84 Median : -1.636 Median : 252.0
Mean : 0.3992 Mean :41.47 Mean : -1.781 Mean : 340.2
3rd Qu.: 0.0000 3rd Qu.:42.70 3rd Qu.: 1.521 3rd Qu.: 541.0
Max. :907.0000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-109.0 Min. :-189.00 Min. : 0.000
1st Qu.:14.0 1st Qu.: 146.0 1st Qu.: 43.00 1st Qu.: 0.000
Median :27.0 Median : 202.0 Median : 95.00 Median : 2.000
Mean :26.6 Mean : 203.7 Mean : 94.39 Mean : 9.227
3rd Qu.:39.0 3rd Qu.: 269.0 3rd Qu.: 149.00 3rd Qu.: 13.000
Max. :53.0 Max. : 442.0 Max. : 272.00 Max. :200.000
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :28.31 Min. :-16.499
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:39.56 1st Qu.: -4.010
Median :0 Median : 0.0000 Median :41.31 Median : -1.033
Mean :0 Mean : 0.6587 Mean :40.75 Mean : -1.485
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:42.18 3rd Qu.: 1.363
Max. :0 Max. :1073.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 58.0
Median : 336.0
Mean : 503.9
3rd Qu.: 735.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. : 1.0 Min. :-51.0 Min. : 0.000 Min. :0
1st Qu.:13.0 1st Qu.:211.0 1st Qu.:149.0 1st Qu.: 0.000 1st Qu.:0
Median :26.0 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.3 Mean :229.7 Mean :165.3 Mean : 5.343 Mean :0
3rd Qu.:39.0 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.0 Max. :384.0 Max. :263.0 Max. :155.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.03 Mean : 369.2
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-58.0 Min. :-103.00 Min. :193.0 Min. :0
1st Qu.:10.00 1st Qu.:102.0 1st Qu.: 42.00 1st Qu.:233.0 1st Qu.:0
Median :40.00 Median :139.0 Median : 80.50 Median :256.5 Median :0
Mean :29.92 Mean :135.9 Mean : 73.51 Mean :282.0 Mean :0
3rd Qu.:46.00 3rd Qu.:182.2 3rd Qu.: 117.00 3rd Qu.:309.2 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. : 217.00 Max. :690.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -5.742 1st Qu.: 66.7
Median : 0.000 Median :42.12 Median : -1.033 Median : 261.0
Mean : 5.531 Mean :40.78 Mean : -2.630 Mean : 696.9
3rd Qu.: 0.000 3rd Qu.:42.53 3rd Qu.: 1.168 3rd Qu.:1055.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-43 Min. :-80.00 Min. : 25.00 Min. :0
1st Qu.:13.00 1st Qu.:135 1st Qu.: 56.00 1st Qu.: 50.00 1st Qu.:0
Median :22.00 Median :170 Median : 87.00 Median : 65.00 Median :0
Mean :25.97 Mean :175 Mean : 88.62 Mean : 75.76 Mean :0
3rd Qu.:42.00 3rd Qu.:211 3rd Qu.:120.00 3rd Qu.: 91.00 3rd Qu.:0
Max. :53.00 Max. :407 Max. :247.00 Max. :223.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.95 1st Qu.: -4.846 1st Qu.: 58.0
Median : 0.0000 Median :41.84 Median : -1.636 Median : 252.0
Mean : 0.3992 Mean :41.47 Mean : -1.781 Mean : 340.2
3rd Qu.: 0.0000 3rd Qu.:42.70 3rd Qu.: 1.521 3rd Qu.: 541.0
Max. :907.0000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-35.0 Min. :-189.0 Min. : 0.000 Min. :0
1st Qu.:14.00 1st Qu.:155.0 1st Qu.: 50.0 1st Qu.: 0.000 1st Qu.:0
Median :27.00 Median :209.0 Median : 101.0 Median : 2.000 Median :0
Mean :26.61 Mean :212.5 Mean : 100.3 Mean : 7.496 Mean :0
3rd Qu.:39.00 3rd Qu.:273.0 3rd Qu.: 152.0 3rd Qu.:12.000 3rd Qu.:0
Max. :53.00 Max. :442.0 Max. : 272.0 Max. :65.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.49 1st Qu.:-4.127 1st Qu.: 52.0
Median : 0.0000 Median :41.17 Median :-1.229 Median : 261.0
Mean : 0.1024 Mean :40.64 Mean :-1.647 Mean : 379.5
3rd Qu.: 0.0000 3rd Qu.:42.05 3rd Qu.: 1.201 3rd Qu.: 656.0
Max. :757.0000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. : 1.0 Min. :-51.0 Min. : 0.000 Min. :0
1st Qu.:13.0 1st Qu.:211.0 1st Qu.:149.0 1st Qu.: 0.000 1st Qu.:0
Median :26.0 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.3 Mean :229.7 Mean :165.3 Mean : 5.343 Mean :0
3rd Qu.:39.0 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.0 Max. :384.0 Max. :263.0 Max. :155.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.03 Mean : 369.2
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-175.00 Min. : 0.00
1st Qu.:14.00 1st Qu.: 28.00 1st Qu.: -34.00 1st Qu.: 4.00
Median :27.00 Median : 78.00 Median : 10.00 Median : 20.00
Mean :26.56 Mean : 83.96 Mean : 13.55 Mean : 32.89
3rd Qu.:39.00 3rd Qu.: 139.00 3rd Qu.: 64.00 3rd Qu.: 50.00
Max. :53.00 Max. : 299.00 Max. : 183.00 Max. :200.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.29 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.264 Mean :42.27 Mean : 0.7201
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. :1097
1st Qu.:1971
Median :2247
Mean :2204
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-58.0 Min. :-103.00 Min. :193.0 Min. :0
1st Qu.:10.00 1st Qu.:102.0 1st Qu.: 42.00 1st Qu.:233.0 1st Qu.:0
Median :40.00 Median :139.0 Median : 80.50 Median :256.5 Median :0
Mean :29.92 Mean :135.9 Mean : 73.51 Mean :282.0 Mean :0
3rd Qu.:46.00 3rd Qu.:182.2 3rd Qu.: 117.00 3rd Qu.:309.2 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. : 217.00 Max. :690.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -5.742 1st Qu.: 66.7
Median : 0.000 Median :42.12 Median : -1.033 Median : 261.0
Mean : 5.531 Mean :40.78 Mean : -2.630 Mean : 696.9
3rd Qu.: 0.000 3rd Qu.:42.53 3rd Qu.: 1.168 3rd Qu.:1055.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-43 Min. :-80.00 Min. : 25.00 Min. :0
1st Qu.:13.00 1st Qu.:135 1st Qu.: 56.00 1st Qu.: 50.00 1st Qu.:0
Median :22.00 Median :170 Median : 87.00 Median : 65.00 Median :0
Mean :25.97 Mean :175 Mean : 88.62 Mean : 75.76 Mean :0
3rd Qu.:42.00 3rd Qu.:211 3rd Qu.:120.00 3rd Qu.: 91.00 3rd Qu.:0
Max. :53.00 Max. :407 Max. :247.00 Max. :223.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.95 1st Qu.: -4.846 1st Qu.: 58.0
Median : 0.0000 Median :41.84 Median : -1.636 Median : 252.0
Mean : 0.3992 Mean :41.47 Mean : -1.781 Mean : 340.2
3rd Qu.: 0.0000 3rd Qu.:42.70 3rd Qu.: 1.521 3rd Qu.: 541.0
Max. :907.0000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-35.0 Min. :-155 Min. : 0.000 Min. :0
1st Qu.:24.00 1st Qu.:176.0 1st Qu.: 76 1st Qu.: 0.000 1st Qu.:0
Median :33.00 Median :238.0 Median : 124 Median : 1.000 Median :0
Mean :32.77 Mean :231.9 Mean : 119 Mean : 7.454 Mean :0
3rd Qu.:43.00 3rd Qu.:290.0 3rd Qu.: 166 3rd Qu.:11.000 3rd Qu.:0
Max. :53.00 Max. :442.0 Max. : 272 Max. :65.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:38.99 1st Qu.:-5.498 1st Qu.: 44.0
Median : 0.0000 Median :41.15 Median :-2.138 Median : 196.0
Mean : 0.0811 Mean :40.55 Mean :-2.157 Mean : 350.2
3rd Qu.: 0.0000 3rd Qu.:42.12 3rd Qu.: 1.026 3rd Qu.: 611.0
Max. :757.0000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. : 1.0 Min. :-51.0 Min. : 0.000 Min. :0
1st Qu.:13.0 1st Qu.:211.0 1st Qu.:149.0 1st Qu.: 0.000 1st Qu.:0
Median :26.0 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.3 Mean :229.7 Mean :165.3 Mean : 5.343 Mean :0
3rd Qu.:39.0 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.0 Max. :384.0 Max. :263.0 Max. :155.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.03 Mean : 369.2
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-26.0 Min. :-189 Min. : 0.000 Min. :0
1st Qu.: 5.000 1st Qu.:124.0 1st Qu.: 16 1st Qu.: 0.000 1st Qu.:0
Median : 9.000 Median :159.0 Median : 47 Median : 3.000 Median :0
Mean : 9.986 Mean :160.2 Mean : 50 Mean : 7.608 Mean :0
3rd Qu.:14.000 3rd Qu.:194.0 3rd Qu.: 81 3rd Qu.:12.000 3rd Qu.:0
Max. :26.000 Max. :368.0 Max. : 243 Max. :57.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :36.85 Min. :-5.7333 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.30 1st Qu.:-1.8853 1st Qu.: 69.0
Median : 0.0000 Median :41.19 Median : 0.5356 Median : 427.0
Mean : 0.1599 Mean :40.87 Mean :-0.2711 Mean : 458.5
3rd Qu.: 0.0000 3rd Qu.:41.84 3rd Qu.: 1.6331 3rd Qu.: 785.0
Max. :458.0000 Max. :43.36 Max. : 4.2156 Max. :1894.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-175.00 Min. : 0.00
1st Qu.:14.00 1st Qu.: 28.00 1st Qu.: -34.00 1st Qu.: 4.00
Median :27.00 Median : 78.00 Median : 10.00 Median : 20.00
Mean :26.56 Mean : 83.96 Mean : 13.55 Mean : 32.89
3rd Qu.:39.00 3rd Qu.: 139.00 3rd Qu.: 64.00 3rd Qu.: 50.00
Max. :53.00 Max. : 299.00 Max. : 183.00 Max. :200.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.29 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.264 Mean :42.27 Mean : 0.7201
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. :1097
1st Qu.:1971
Median :2247
Mean :2204
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-58.0 Min. :-103.00 Min. :193.0 Min. :0
1st Qu.:10.00 1st Qu.:102.0 1st Qu.: 42.00 1st Qu.:233.0 1st Qu.:0
Median :40.00 Median :139.0 Median : 80.50 Median :256.5 Median :0
Mean :29.92 Mean :135.9 Mean : 73.51 Mean :282.0 Mean :0
3rd Qu.:46.00 3rd Qu.:182.2 3rd Qu.: 117.00 3rd Qu.:309.2 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. : 217.00 Max. :690.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -5.742 1st Qu.: 66.7
Median : 0.000 Median :42.12 Median : -1.033 Median : 261.0
Mean : 5.531 Mean :40.78 Mean : -2.630 Mean : 696.9
3rd Qu.: 0.000 3rd Qu.:42.53 3rd Qu.: 1.168 3rd Qu.:1055.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-43.0 Min. :-76.0 Min. : 92.0 Min. :0
1st Qu.:12.00 1st Qu.:130.0 1st Qu.: 61.0 1st Qu.:113.0 1st Qu.:0
Median :34.00 Median :162.0 Median : 88.0 Median :129.0 Median :0
Mean :28.69 Mean :164.9 Mean : 89.7 Mean :136.7 Mean :0
3rd Qu.:45.00 3rd Qu.:196.0 3rd Qu.:119.0 3rd Qu.:156.0 3rd Qu.:0
Max. :53.00 Max. :407.0 Max. :228.0 Max. :223.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.06 1st Qu.: -5.733 1st Qu.: 43.3
Median : 0.000 Median :41.98 Median : -1.787 Median : 150.0
Mean : 1.628 Mean :41.40 Mean : -2.129 Mean : 297.4
3rd Qu.: 0.000 3rd Qu.:42.87 3rd Qu.: 1.768 3rd Qu.: 421.0
Max. :907.000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-35.0 Min. :-155.0 Min. : 0.000 Min. :0
1st Qu.:26.00 1st Qu.:174.0 1st Qu.: 73.0 1st Qu.: 0.000 1st Qu.:0
Median :34.00 Median :240.0 Median : 123.0 Median : 2.000 Median :0
Mean :34.29 Mean :230.8 Mean : 116.6 Mean : 7.549 Mean :0
3rd Qu.:44.00 3rd Qu.:290.0 3rd Qu.: 164.0 3rd Qu.:12.000 3rd Qu.:0
Max. :53.00 Max. :442.0 Max. : 272.0 Max. :64.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :36.85 Min. :-8.624 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.70 1st Qu.:-3.808 1st Qu.: 69.0
Median : 0.0000 Median :41.57 Median :-1.008 Median : 336.0
Mean : 0.0992 Mean :41.37 Mean :-1.437 Mean : 404.1
3rd Qu.: 0.0000 3rd Qu.:42.33 3rd Qu.: 1.384 3rd Qu.: 667.0
Max. :757.0000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 52.0 Min. :-65.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:180.0 1st Qu.: 86.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :228.0 Median :130.0 Median : 0.000 Median :0
Mean :26.25 Mean :236.8 Mean :129.4 Mean : 7.046 Mean :0
3rd Qu.:39.00 3rd Qu.:289.0 3rd Qu.:177.0 3rd Qu.: 9.000 3rd Qu.:0
Max. :53.00 Max. :431.0 Max. :269.0 Max. :65.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.000000 Min. :35.28 Min. :-6.949 Min. : 1.0
1st Qu.:0.000000 1st Qu.:36.64 1st Qu.:-6.257 1st Qu.: 21.0
Median :0.000000 Median :37.16 Median :-5.600 Median : 34.0
Mean :0.003015 Mean :37.02 Mean :-5.261 Mean :117.4
3rd Qu.:0.000000 3rd Qu.:37.42 3rd Qu.:-4.488 3rd Qu.: 90.0
Max. :4.000000 Max. :39.47 Max. :-1.169 Max. :582.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. : 1.0 Min. :-51.0 Min. : 0.000 Min. :0
1st Qu.:13.0 1st Qu.:211.0 1st Qu.:149.0 1st Qu.: 0.000 1st Qu.:0
Median :26.0 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.3 Mean :229.7 Mean :165.3 Mean : 5.343 Mean :0
3rd Qu.:39.0 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.0 Max. :384.0 Max. :263.0 Max. :155.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.03 Mean : 369.2
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 8.0 Min. :-80.00 Min. : 25.00 Min. :0
1st Qu.:13.00 1st Qu.:136.0 1st Qu.: 55.00 1st Qu.: 48.00 1st Qu.:0
Median :21.00 Median :173.0 Median : 86.00 Median : 59.00 Median :0
Mean :25.35 Mean :177.4 Mean : 88.37 Mean : 61.75 Mean :0
3rd Qu.:41.00 3rd Qu.:215.0 3rd Qu.:121.00 3rd Qu.: 74.25 3rd Qu.:0
Max. :53.00 Max. :376.0 Max. :247.00 Max. :110.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :35.28 Min. :-8.624 Min. : 1
1st Qu.: 0.0000 1st Qu.:40.93 1st Qu.:-4.680 1st Qu.: 61
Median : 0.0000 Median :41.83 Median :-1.411 Median : 261
Mean : 0.1166 Mean :41.49 Mean :-1.701 Mean : 350
3rd Qu.: 0.0000 3rd Qu.:42.59 3rd Qu.: 1.512 3rd Qu.: 566
Max. :93.0000 Max. :43.57 Max. : 4.216 Max. :1405
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-26.0 Min. :-189 Min. : 0.000 Min. :0
1st Qu.: 5.000 1st Qu.:124.0 1st Qu.: 16 1st Qu.: 0.000 1st Qu.:0
Median : 9.000 Median :159.0 Median : 47 Median : 3.000 Median :0
Mean : 9.986 Mean :160.2 Mean : 50 Mean : 7.608 Mean :0
3rd Qu.:14.000 3rd Qu.:194.0 3rd Qu.: 81 3rd Qu.:12.000 3rd Qu.:0
Max. :26.000 Max. :368.0 Max. : 243 Max. :57.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :36.85 Min. :-5.7333 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.30 1st Qu.:-1.8853 1st Qu.: 69.0
Median : 0.0000 Median :41.19 Median : 0.5356 Median : 427.0
Mean : 0.1599 Mean :40.87 Mean :-0.2711 Mean : 458.5
3rd Qu.: 0.0000 3rd Qu.:41.84 3rd Qu.: 1.6331 3rd Qu.: 785.0
Max. :458.0000 Max. :43.36 Max. : 4.2156 Max. :1894.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-175.00 Min. : 0.00
1st Qu.:14.00 1st Qu.: 28.00 1st Qu.: -34.00 1st Qu.: 4.00
Median :27.00 Median : 78.00 Median : 10.00 Median : 20.00
Mean :26.56 Mean : 83.96 Mean : 13.55 Mean : 32.89
3rd Qu.:39.00 3rd Qu.: 139.00 3rd Qu.: 64.00 3rd Qu.: 50.00
Max. :53.00 Max. : 299.00 Max. : 183.00 Max. :200.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.29 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.264 Mean :42.27 Mean : 0.7201
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. :1097
1st Qu.:1971
Median :2247
Mean :2204
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-58.0 Min. :-103.00 Min. :193.0 Min. :0
1st Qu.:10.00 1st Qu.:102.0 1st Qu.: 42.00 1st Qu.:233.0 1st Qu.:0
Median :40.00 Median :139.0 Median : 80.50 Median :256.5 Median :0
Mean :29.92 Mean :135.9 Mean : 73.51 Mean :282.0 Mean :0
3rd Qu.:46.00 3rd Qu.:182.2 3rd Qu.: 117.00 3rd Qu.:309.2 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. : 217.00 Max. :690.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -5.742 1st Qu.: 66.7
Median : 0.000 Median :42.12 Median : -1.033 Median : 261.0
Mean : 5.531 Mean :40.78 Mean : -2.630 Mean : 696.9
3rd Qu.: 0.000 3rd Qu.:42.53 3rd Qu.: 1.168 3rd Qu.:1055.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-43.0 Min. :-76.0 Min. : 92.0 Min. :0
1st Qu.:12.00 1st Qu.:130.0 1st Qu.: 61.0 1st Qu.:113.0 1st Qu.:0
Median :34.00 Median :162.0 Median : 88.0 Median :129.0 Median :0
Mean :28.69 Mean :164.9 Mean : 89.7 Mean :136.7 Mean :0
3rd Qu.:45.00 3rd Qu.:196.0 3rd Qu.:119.0 3rd Qu.:156.0 3rd Qu.:0
Max. :53.00 Max. :407.0 Max. :228.0 Max. :223.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.06 1st Qu.: -5.733 1st Qu.: 43.3
Median : 0.000 Median :41.98 Median : -1.787 Median : 150.0
Mean : 1.628 Mean :41.40 Mean : -2.129 Mean : 297.4
3rd Qu.: 0.000 3rd Qu.:42.87 3rd Qu.: 1.768 3rd Qu.: 421.0
Max. :907.000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. :13.0 Min. :-31.0 Min. :-67.00 Min. : 0.00 Min. :0
1st Qu.:27.0 1st Qu.:195.0 1st Qu.: 93.75 1st Qu.: 0.00 1st Qu.:0
Median :35.0 Median :255.0 Median :145.00 Median : 1.00 Median :0
Mean :35.3 Mean :243.1 Mean :135.32 Mean : 6.14 Mean :0
3rd Qu.:44.0 3rd Qu.:295.0 3rd Qu.:182.00 3rd Qu.: 9.00 3rd Qu.:0
Max. :53.0 Max. :442.0 Max. :272.00 Max. :51.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :36.85 Min. :-6.0442 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:40.82 1st Qu.: 0.3056 1st Qu.: 32.0
Median : 0.00000 Median :41.43 Median : 0.8564 Median : 91.0
Mean : 0.01134 Mean :41.15 Mean : 0.7660 Mean :175.7
3rd Qu.: 0.00000 3rd Qu.:41.96 3rd Qu.: 2.0697 3rd Qu.:287.0
Max. :290.00000 Max. :43.57 Max. : 4.2156 Max. :691.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 52.0 Min. :-65.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:180.0 1st Qu.: 86.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :228.0 Median :130.0 Median : 0.000 Median :0
Mean :26.25 Mean :236.8 Mean :129.4 Mean : 7.046 Mean :0
3rd Qu.:39.00 3rd Qu.:289.0 3rd Qu.:177.0 3rd Qu.: 9.000 3rd Qu.:0
Max. :53.00 Max. :431.0 Max. :269.0 Max. :65.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.000000 Min. :35.28 Min. :-6.949 Min. : 1.0
1st Qu.:0.000000 1st Qu.:36.64 1st Qu.:-6.257 1st Qu.: 21.0
Median :0.000000 Median :37.16 Median :-5.600 Median : 34.0
Mean :0.003015 Mean :37.02 Mean :-5.261 Mean :117.4
3rd Qu.:0.000000 3rd Qu.:37.42 3rd Qu.:-4.488 3rd Qu.: 90.0
Max. :4.000000 Max. :39.47 Max. :-1.169 Max. :582.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. : 1.0 Min. :-51.0 Min. : 0.000 Min. :0
1st Qu.:13.0 1st Qu.:211.0 1st Qu.:149.0 1st Qu.: 0.000 1st Qu.:0
Median :26.0 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.3 Mean :229.7 Mean :165.3 Mean : 5.343 Mean :0
3rd Qu.:39.0 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.0 Max. :384.0 Max. :263.0 Max. :155.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.03 Mean : 369.2
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 40.0 Min. :-68.00 Min. : 0.00 Min. :0
1st Qu.:13.00 1st Qu.:151.0 1st Qu.: 67.00 1st Qu.: 1.00 1st Qu.:0
Median :27.00 Median :194.0 Median :102.00 Median : 8.00 Median :0
Mean :26.15 Mean :194.7 Mean : 99.13 Mean :12.35 Mean :0
3rd Qu.:38.00 3rd Qu.:233.0 3rd Qu.:135.00 3rd Qu.:21.00 3rd Qu.:0
Max. :53.00 Max. :398.0 Max. :207.00 Max. :58.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :42.24 Min. :-8.624 Min. : 5
1st Qu.: 0.00000 1st Qu.:42.56 1st Qu.:-8.411 1st Qu.: 58
Median : 0.00000 Median :43.31 Median :-7.456 Median :127
Mean : 0.05507 Mean :43.04 Mean :-7.001 Mean :200
3rd Qu.: 0.00000 3rd Qu.:43.43 3rd Qu.:-5.873 3rd Qu.:336
Max. :177.00000 Max. :43.57 Max. :-2.906 Max. :534
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. :17.00 Min. :-35.0 Min. :-155.0 Min. : 0.000 Min. :0
1st Qu.:28.00 1st Qu.:157.0 1st Qu.: 51.0 1st Qu.: 0.000 1st Qu.:0
Median :36.00 Median :243.0 Median : 104.0 Median : 2.000 Median :0
Mean :36.15 Mean :227.7 Mean : 96.5 Mean : 7.627 Mean :0
3rd Qu.:44.00 3rd Qu.:297.0 3rd Qu.: 144.0 3rd Qu.:11.000 3rd Qu.:0
Max. :53.00 Max. :402.0 Max. : 266.0 Max. :64.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :37.13 Min. :-6.600 Min. : 405.0
1st Qu.: 0.0000 1st Qu.:40.38 1st Qu.:-4.049 1st Qu.: 656.0
Median : 0.0000 Median :40.95 Median :-3.450 Median : 788.0
Mean : 0.2444 Mean :41.00 Mean :-2.352 Mean : 818.5
3rd Qu.: 0.0000 3rd Qu.:41.84 3rd Qu.:-1.117 3rd Qu.: 945.0
Max. :757.0000 Max. :42.87 Max. : 2.438 Max. :1894.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 8.0 Min. :-80.00 Min. : 25.00 Min. :0
1st Qu.:13.00 1st Qu.:136.0 1st Qu.: 55.00 1st Qu.: 48.00 1st Qu.:0
Median :21.00 Median :173.0 Median : 86.00 Median : 59.00 Median :0
Mean :25.35 Mean :177.4 Mean : 88.37 Mean : 61.75 Mean :0
3rd Qu.:41.00 3rd Qu.:215.0 3rd Qu.:121.00 3rd Qu.: 74.25 3rd Qu.:0
Max. :53.00 Max. :376.0 Max. :247.00 Max. :110.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :35.28 Min. :-8.624 Min. : 1
1st Qu.: 0.0000 1st Qu.:40.93 1st Qu.:-4.680 1st Qu.: 61
Median : 0.0000 Median :41.83 Median :-1.411 Median : 261
Mean : 0.1166 Mean :41.49 Mean :-1.701 Mean : 350
3rd Qu.: 0.0000 3rd Qu.:42.59 3rd Qu.: 1.512 3rd Qu.: 566
Max. :93.0000 Max. :43.57 Max. : 4.216 Max. :1405
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-26.0 Min. :-189 Min. : 0.000 Min. :0
1st Qu.: 5.000 1st Qu.:124.0 1st Qu.: 16 1st Qu.: 0.000 1st Qu.:0
Median : 9.000 Median :159.0 Median : 47 Median : 3.000 Median :0
Mean : 9.986 Mean :160.2 Mean : 50 Mean : 7.608 Mean :0
3rd Qu.:14.000 3rd Qu.:194.0 3rd Qu.: 81 3rd Qu.:12.000 3rd Qu.:0
Max. :26.000 Max. :368.0 Max. : 243 Max. :57.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :36.85 Min. :-5.7333 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.30 1st Qu.:-1.8853 1st Qu.: 69.0
Median : 0.0000 Median :41.19 Median : 0.5356 Median : 427.0
Mean : 0.1599 Mean :40.87 Mean :-0.2711 Mean : 458.5
3rd Qu.: 0.0000 3rd Qu.:41.84 3rd Qu.: 1.6331 3rd Qu.: 785.0
Max. :458.0000 Max. :43.36 Max. : 4.2156 Max. :1894.0
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-175.00 Min. : 0.00
1st Qu.:14.00 1st Qu.: 28.00 1st Qu.: -34.00 1st Qu.: 4.00
Median :27.00 Median : 78.00 Median : 10.00 Median : 20.00
Mean :26.56 Mean : 83.96 Mean : 13.55 Mean : 32.89
3rd Qu.:39.00 3rd Qu.: 139.00 3rd Qu.: 64.00 3rd Qu.: 50.00
Max. :53.00 Max. : 299.00 Max. : 183.00 Max. :200.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.29 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.264 Mean :42.27 Mean : 0.7201
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. :1097
1st Qu.:1971
Median :2247
Mean :2204
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-58.0 Min. :-103.00 Min. :193.0 Min. :0
1st Qu.:10.00 1st Qu.:102.0 1st Qu.: 42.00 1st Qu.:233.0 1st Qu.:0
Median :40.00 Median :139.0 Median : 80.50 Median :256.5 Median :0
Mean :29.92 Mean :135.9 Mean : 73.51 Mean :282.0 Mean :0
3rd Qu.:46.00 3rd Qu.:182.2 3rd Qu.: 117.00 3rd Qu.:309.2 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. : 217.00 Max. :690.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -5.742 1st Qu.: 66.7
Median : 0.000 Median :42.12 Median : -1.033 Median : 261.0
Mean : 5.531 Mean :40.78 Mean : -2.630 Mean : 696.9
3rd Qu.: 0.000 3rd Qu.:42.53 3rd Qu.: 1.168 3rd Qu.:1055.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)